/**
 * by Butnet's Frame Creator
 */
#if class.package
package ${class.package};
#end

#for i in class.imports
import ${.i};
#end

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.commons.beanutils.BeanUtils;
import com.butnet.myframe.actions.BaseDispatchAction;
import com.butnet.myframe.hql.query.PageList;

#if class.commet
/**
 * ${class.commet}
 */
#end
public class ${class.name}Action extends BaseDispatchAction {
	/**
	 * 示例
	 */
	public ActionForward example(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		ServiceFactory serviceFactory = (ServiceFactory) getServiceFactory();
		${class.name}Form form = (${class.name}Form) actionForm;
		${class.attributes.model} ${class.attributes.modelName} = null;
		
		//TODO: add your code
		
		return null;
	}
	public ${class.name} create(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		ServiceFactory serviceFactory = (ServiceFactory) getServiceFactory();
		${class.name}Form form = (${class.name}Form) actionForm;
		${class.name} ${class.fname} = new ${class.name}();
		BeanUtils.copyProperties(${class.fname}, form);
		return serviceFactory.get${class.name}Service().create(${class.fname});
	}
	public ActionForward delete(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		ServiceFactory serviceFactory = (ServiceFactory) getServiceFactory();
		${class.name}Form form = (${class.name}Form) actionForm;
		serviceFactory.get${class.name}Service().delete(form.getId());
		return null;
	}
	public List<${class.name}> list(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		ServiceFactory serviceFactory = (ServiceFactory) getServiceFactory();
		List<${class.name}> list = serviceFactory.get${class.name}Service().list();
		request.setAttribute("${class.fname}s", list);
		return list;
	}
	public PageList<${class.name}> pageList(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		ServiceFactory serviceFactory = (ServiceFactory) getServiceFactory();
		${class.name}Form form = (${class.name}Form) actionForm;
		PageList<${class.name}> pl = serviceFactory.get${class.name}Service().pageList(form.getPageIndex(), form.getPageCount());
		request.setAttribute("${class.fname}PageList", pl);
		return pl;
	}
}